package com.jd.webapp.portal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.jd.search.pojo.SearchResult;
import com.jd.search.service.SearchService;

@Controller
public class SearchController {
	@Autowired
	private SearchService searchService;
	
	@RequestMapping("/search")
	public String search(String q,@RequestParam(defaultValue="1")int page,
			@RequestParam(defaultValue="60")int rows,Model model){
		try {
			SearchResult searchResult = searchService.searchGoods(q, page, rows);
			model.addAttribute("query", q);
			model.addAttribute("totalPages", searchResult.getTotal());
			model.addAttribute("goodsList", searchResult.getGoods());
			model.addAttribute("page", page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "search";
	}
}
